package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"market/marketrpc/internal/svc"
	"market/marketrpc/marketrpc"
	"market/model/mysql"
)

type ProductAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductAddLogic {
	return &ProductAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProductAddLogic) ProductAdd(in *marketrpc.ProductAddRequest) (*marketrpc.ProductAddResponse, error) {
	// todo: add your logic here and delete this line
	shop := mysql.Products{
		Name:   in.Name,
		Price:  float64(in.Price),
		Class:  in.Class,
		Status: in.Status,
		UserId: int(in.Userid),
	}
	mysql.DB.Debug().Create(&shop)
	return &marketrpc.ProductAddResponse{Id: int64(shop.ID)}, nil
}
